const sqlite3 = require("sqlite3").verbose()
const path = require("path")

var db = new sqlite3.Database(path.join(__dirname, "ld.message.sqlite3"))

db.async = {}

db.async.all = (sql:string, params:[]) => {
    return new Promise((resolve, reject) => {
        db.all(sql, params, (err:any, rows:{}) => {
            resolve({ err, rows })
        })
    })
}

db.async.run = (sql:string, params:[]) => {
    return new Promise((resolve, reject) => {
        db.run(sql, params, (err:any, rows:{}) => {
            resolve({ err, rows })
        })
    })
}

module.exports =  {db}

